@extends('home.base.user')
@section('content')
<form action="" method="post" name="myform">
    <input type="hidden" name="_token" value="{{csrf_token()}}">
    <input type="hidden" name="_method" value="DELETE">
</form>
<div class="content container">
	<div class="f_r personal_r">
		<div class="personal_r_t"></div>
		<div class="personal_r_m">
			<div class="personal_r_m_t">
				<h2>修改送货信息</h2>
			</div><!--personal_r_m_t end-->
			<div class="personal_r_m_m">
				<div class="order">
					<div class="ytx">
						<div class="now_address">
							<div class="now_address_t">
								<h3 class="f_l">现有地址</h3>

							</div><!--now_address_t end-->
							<div class="now_address_l">
								<ul>
                                    @foreach($address as $v)
                                    <li class="cur" id="ra1">
										<div class="f_l">
											<label for="rad1"><strong>{{$v->consignee}}</strong>
                                                <span>{{$v->province}}{{$v->city}}{{$v->country}}{{$v->adddetail}}</span>
                                            </label>
										</div>

										<div class="f_r"><a href="javascript:doDel({{$v->id}})" class="red">[删除]</a></div>
									</li>
									@endforeach
								</ul>
							</div><!--now_address_l end-->
						</div><!--now_address end-->

						<div class="blank10"></div>
                        <script type="text/javascript">
                        function doDel(id)
                        {
                            if(confirm("确定删除该地址？")){
                                var form = document.myform;
                                form.action = "/home1/editaddress/"+id;
                                form.submit();
                            }
                        }
                        </script>
                    <form method="post" action="" id="" name="ready">
                        <input type='hidden' name='_token' value='{{ csrf_token() }}'>
                        <input type="hidden" name="uid" value="{{session()->get('homeuser')->id}}">
						<table>
							<tbody>
								<tr>
									<td width="76px" class="a-r"><span class="red">*</span>收货人：</td><td><input type="text" name="consignee" value="{{session()->get('homeuser')->realname}}" id="" class="input-text" size="38" /></td>
								</tr>
								<tr>
									<td class="a-r"><span class="red">*</span>地区：</td>
                                    <td>
                                        <select name="province" id="cid">
                                            <option>--请选择--</option>
                                        </select>&nbsp;&nbsp;市：
                                        <select name="city">
                                            <option>--请选择--</option>
                                        </select>&nbsp;&nbsp;县/区：
                                        <select name="country">
                                            <option>--请选择--</option>
                                        </select>
                                    </td>
								</tr>
								<tr>
									<td class="a-r"><span class="red">*</span>收货地址：</td><td><input type="text" value="" name="adddetail" id="" class="input-text" size="60" /></td>
								</tr>
								<tr>
									<td class="a-r"><span class="red">*</span>联系方式：</td><td><input value="" type="text" name="phone" id="" class="input-text" size="38" />&nbsp;&nbsp;用于接收发货通知短信及送货前确认</td>
								</tr>
								<tr>
									<td class="a-r">邮政编码：</td><td><input type="text" value="" name="code" id="" class="input-text" size="14" />&nbsp;&nbsp;有助于快速确定送货地址</td>
								</tr>
								<tr>
									<td></td><td height="50px"><a class="yellow" href="javascript:addad()">[添加到常用地址]</a></td>
								</tr>
							</tbody>
						</table>
					</form>
                    <script type="text/javascript">
                        function addad()
                        {
                            var form = document.ready;
                            form.action = "/home1/editaddress";
                            form.submit();
                        }
                    </script>
					</div>
				</div><!--order end-->
			</div><!--comment end-->
		</div><!--personal_r_m end-->
		<div class="personal_r_b"></div>
	</div><!--personal_r end-->

	<script language="javascript" src="js/jquery.checkboxes.js"></script>

	<div class="clear mb-10"></div>
    <script type="text/javascript" src='{{asset("ajax/jquery-1.8.3.min.js") }}'></script>
    <script type="text/javascript">
        var j = jQuery.noConflict(true);
    </script>
    <script type="text/javascript">
        var url = "{{ url('aja/get') }}";
        j.ajax({
            url:url,
            async:false,
            data:{upid:0},
            type:'get',
            dataType:'json',
            error:function()
            {
                alert('ajax请求失败');
            },
            success:function(data)
            {
                console.log(data);
                for (var i = 0; i < data.length; i++) {
                    j('#cid').append("<option value='"+data[i].id+"'>"+data[i].name+"</option>");
                };
            }
        });

        j("select").live("change",function(){
            //先清除后面的select，再添加新的select
            var ob = j(this);
            if(j(this).val() != '--请选择--'){
                var upid = $(this).val();
                j.ajax({
                    url:'/aja/post',
                    async:false,
                    type:'post',
                    data:{upid:upid},
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    },
                    dataType:'json',
                    error:function()
                    {
                        alert('ajax请求失败');
                    },
                    success:function(data)
                    {
                        if(data.length>0){
                            var select = ob.next('select');
                            j(select).children('option').remove();
                            j(select).append("<option>--请选择--</option>");
                            for (var i = 0; i < data.length; i++) {
                                j(select).append("<option value='"+data[i].id+"'>"+data[i].name+"</option>");
                            };
                        }
                    }
                });
            }
        });
    </script>
</div>
@stop
